package cn.itcast.order.service;

import cn.itcast.feign.clients.UserClient;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserClient userClient;







    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        // 2.通过feign对远程的代码进行调用
        User user = userClient.queryById(order.getUserId());

        // 4.返回

        System.out.println("00044" + user);
        System.out.println("00055" + order);
        order.setUser(user);
        System.out.println("00066" + order);
        return order;
    }






/*

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        String url = "http://user-server/user/" + order.getUserId();
        //String url = "http://user-service/user/" + order.getUserId();
        User user = restTemplate.getForObject(url, User.class);
        // 4.返回
       // User user = restTemplate.getForObject("http://localhost:8088/user/1", User.class);
        System.out.println("00044" + user);
        System.out.println("00055" + order);
        order.setUser(user);
        System.out.println("00066" + order);
        return order;
    }

    */












}
